
package com.blackline.auto.Others;

import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

import com.blackline.auto.common.CommonMethods;
import com.blackline.declareUI.UI;
import com.blackline.parameters.Parameters;

/**
 * @author XBO
 * @version Feb, 2013
 * <p>The smoke test to Others module.
 */
public class Others_smoketest {
	
	private WebDriver driver;
	private StringBuffer verificationErrors = new StringBuffer();
	private static Logger logger=Logger.getLogger(Others_smoketest.class);
	UI UI=new UI();
	Parameters parameters;
	@Before
	public void setUp() throws Exception {
		FirefoxProfile profile=new FirefoxProfile();
		profile.setEnableNativeEvents(true);
		parameters=new Parameters("parameters.xml");

		driver = new FirefoxDriver();
		driver.manage().window().maximize();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		UI.declareAllUI(driver);
	}
	
	@Test
	public void Othersmoketest() throws Exception {

		UI.LogonPage.Login(driver, parameters.urlDev2, parameters.getLogonID("cfo"), parameters.getPassword("cfo"));
		UI.NavigationMenu.REQUESTS.click();
		UI.NavigationMenu.Make_Requests.click();
		
		verificationErrors.append(UI.page.VerifyPageTitle(driver, "Make Requests"));
		UI.SessionMenu.LogOut.click();
		
		UI.LogonPage.Login(driver, parameters.urlDev2, parameters.getLogonID("cfo"), parameters.getPassword("cfo"));
		UI.NavigationMenu.RISK.click();
		
		verificationErrors.append(UI.page.VerifyPageTitle(driver, "Risk Filtering"));
		UI.SessionMenu.LogOut.click();
		
		UI.LogonPage.Login(driver, parameters.urlDev2, parameters.getLogonID("cfo"), parameters.getPassword("cfo"));
		UI.NavigationMenu.EVALUATIONS.click();
		
		verificationErrors.append(UI.page.VerifyPageTitle(driver, "Evaluations"));
		UI.SessionMenu.LogOut.click();
		
	//Notebook
		UI.LogonPage.Login(driver, parameters.urlDev2, parameters.getLogonID("ia"), parameters.getPassword("ia"));
		UI.NavigationMenu.NOTEBOOK.click();
		verificationErrors.append(UI.page.VerifyPageTitle(driver, "Notes"));
		UI.Notes.Add_Note.click();
		
		//Verify new window
		if (UI.page.switchToNewWindow(driver))
		{
			logger.info("[Pass!] New window exists.");
		}
		else
		{
			logger.error("[Fail!] New window does NOT exist.");
			verificationErrors.append("[Fail!] New window does NOT exist.");
		}
		UI.Notes_popupWindow.Close_Window_link.click();

	}
	
	
	@After
	public void tearDown() throws Exception {
		CommonMethods.takeScreenShot(this.getClass(), driver);
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}
	
}
